//
//  EmaOverseaSdkApi.cpp
//
//  Created by galileoliu on 2019/1/10.
//


#include "EmaOverseaSdkApi.hpp"

#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID && CC_TARGET_PLATFORM != CC_PLATFORM_IOS)

std::string EmaOverseaSdkApi::getVersion(){
    std::string ret = "1000000";
    return ret;
}

std::string EmaOverseaSdkApi::getResourceVersion()
{
    std::string ret = "0";
    return ret;
}

std::string EmaOverseaSdkApi::getCdn(){
    std::string ret = "https://test-qa-sh-static-ea.neocraftstudio.com/ea/";
    return ret;
}

bool EmaOverseaSdkApi::isInitialized(){
    return true;
}

void EmaOverseaSdkApi::jumpToAppShop(){
    
}

bool EmaOverseaSdkApi::isReview(){
    return false;
}

void EmaOverseaSdkApi::initSdk(){
    
}

int EmaOverseaSdkApi::getInitSdkState(){
    return 0;
}

bool EmaOverseaSdkApi::checkPermissions(){
    return true;
}
void EmaOverseaSdkApi::requestPermissions(){
    
}

void EmaOverseaSdkApi::goAppSetting(){
    
}

void EmaOverseaSdkApi::activeBuriedPointReport(const char* data){
    
}
// --- eventName 事件名称 active AdJust识别码 result 结果
void EmaOverseaSdkApi::reportActiveBuriedPoint(const char * eventName, int result, int duration){
    
}
#endif

// 版本转换 规则 333.333.333
// 例如： 1012013 转换 1.12.13
std::string EmaOverseaSdkApi::getVersionNum(){
    std::string versionStr = getVersion();

    int len = (int)versionStr.length();
    if(len < 7){
        return "1.0.0";
    }
    int version2 = atoi(versionStr.substr(len - 6, 3).c_str());
    int version3 = atoi(versionStr.substr(len - 3, 3).c_str());
    
    char versionTemp[4] = {0};
    sprintf((char *)versionTemp, "%d", version2);
    std::string version2Str = versionTemp;
    
    sprintf((char *)versionTemp, "%d", version3);
    std::string version3Str = versionTemp;

    return versionStr.substr(0, len - 6) + "." + version2Str + "." + version3Str;
}

std::vector<std::string> EmaOverseaSdkApi::getCdnList(){
    std::vector<std::string> ret;
    std::string strCdn = getCdn();
    while (true) {
        auto index = strCdn.find(";");
        std::string subStr = strCdn.substr(0, index);
        if (!subStr.empty()) {
            // Append automatically "/"
            if (subStr[subStr.size() - 1] != '/') {
                subStr.append("/");
            }
            ret.push_back(subStr);
        }
        strCdn.erase(0, index + 1);
        if (index == -1) {
            break;
        }
    }
    return ret;
}
